import '../utils/date_utils.dart';
import 'paging_model.dart';
import 'result_model.dart';

///学校年级科目-查询-请求
class SchoolGradeSubjectQueryReq extends PagingQueryReq {
  final String schoolId, semesterId;
  final int gradeVal, status;

  SchoolGradeSubjectQueryReq({
    required this.schoolId,
    required this.semesterId,
    required this.gradeVal,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['semesterId'] = semesterId;
    map['gradeVal'] = gradeVal;
    map['status'] = status;
    return map;
  }
}

///学校年级科目-查询-响应
class SchoolGradeSubjectQueryRes
    extends PagingQueryRes<SchoolGradeSubjectItemRes> {
  SchoolGradeSubjectQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolGradeSubjectQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolGradeSubjectItemRes.fromMap(row),
    );
    return SchoolGradeSubjectQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///学校年级科目-数据项-响应
class SchoolGradeSubjectItemRes {
  final String id, schoolId, semesterId, remark;
  final int gradeVal, subjectVal, scoreValue, status;
  final double discount;
  final DateTime? createdAt;

  const SchoolGradeSubjectItemRes({
    required this.id,
    required this.schoolId,
    required this.semesterId,
    required this.gradeVal,
    required this.subjectVal,
    required this.scoreValue,
    required this.discount,
    required this.remark,
    required this.status,
    this.createdAt,
  });

  factory SchoolGradeSubjectItemRes.fromMap(final Map<String, dynamic> map) =>
      SchoolGradeSubjectItemRes(
        id: map['id'] ?? '',
        schoolId: map['schoolId'] ?? '',
        semesterId: map['semesterId'] ?? '',
        gradeVal: map['gradeVal'] ?? 0,
        subjectVal: map['subjectVal'] ?? 0,
        scoreValue: map['scoreValue'] ?? 100,
        discount: map['discount'] ?? 1.0,
        remark: map['remark'] ?? '',
        status: map['status'] ?? 1,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///学校年级科目-加载-响应
class SchoolGradeSubjectInfoRes extends SchoolGradeSubjectItemRes
    with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolGradeSubjectInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolGradeSubjectItemRes item,
  }) : super(
          id: item.id,
          schoolId: item.schoolId,
          semesterId: item.semesterId,
          gradeVal: item.gradeVal,
          subjectVal: item.subjectVal,
          scoreValue: item.scoreValue,
          discount: item.discount,
          remark: item.remark,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolGradeSubjectInfoRes.fromModel(final ResultModelRes res) =>
      SchoolGradeSubjectInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolGradeSubjectItemRes.fromMap(res.toMap),
      );
}

class BaseSchoolGradeSubjectSaveReq {
  final String semesterId, remark;
  final int gradeVal, subjectVal, scoreValue;
  final double discount;

  const BaseSchoolGradeSubjectSaveReq({
    required this.semesterId,
    required this.gradeVal,
    required this.subjectVal,
    required this.scoreValue,
    required this.discount,
    required this.remark,
  });

  Map<String, dynamic> toMap() => {
        'semesterId': semesterId,
        'gradeVal': gradeVal,
        'subjectVal': subjectVal,
        'scoreValue': scoreValue,
        'discount': discount,
        'remark': remark,
      };
}

///学校年级科目-添加-请求
class SchoolGradeSubjectAddReq extends BaseSchoolGradeSubjectSaveReq {
  final String schoolId;

  SchoolGradeSubjectAddReq({
    required this.schoolId,
    required BaseSchoolGradeSubjectSaveReq base,
  }) : super(
          semesterId: base.semesterId,
          gradeVal: base.gradeVal,
          subjectVal: base.subjectVal,
          scoreValue: base.scoreValue,
          discount: base.discount,
          remark: base.remark,
        );
}

///学校年级科目-修改-请求
class SchoolGradeSubjectModifyReq extends BaseSchoolGradeSubjectSaveReq {
  final String id;
  final int status;

  SchoolGradeSubjectModifyReq({
    required this.id,
    required this.status,
    required BaseSchoolGradeSubjectSaveReq base,
  }) : super(
          semesterId: base.semesterId,
          gradeVal: base.gradeVal,
          subjectVal: base.subjectVal,
          scoreValue: base.scoreValue,
          discount: base.discount,
          remark: base.remark,
        );

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['status'] = status;
    return map;
  }
}
